const UPowerGlib = imports.gi.UPowerGlib;
const ConsoleKit = imports.gdm.consoleKit;
+const Systemd = imports.gdm.systemd;
+
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
_init: function() {
this.parent('system-shutdown', null);
this._consoleKitManager = new ConsoleKit.ConsoleKitManager();
+ this._systemdLoginManager = new Systemd.SystemdLoginManager();
this._upClient = new UPowerGlib.Client();
this._createSubMenu();
},
_updateHaveShutdown: function() {
- this._consoleKitManager.CanStopRemote(Lang.bind(this,
- function(result, error) {
- if (!error)
- this._haveShutdown = result;
- else
- this._haveShutdown = false;
-
- if (this._haveShutdown) {
- this._powerOffItem.actor.show();
- } else {
- this._powerOffItem.actor.hide();
- }
- this._updateVisibility();
- }));
+ if (Systemd.haveSystemd()) {
+ this._systemdLoginManager.CanPowerOffRemote(Lang.bind(this,
+ function(result, error) {
+ if (!error)
+ this._haveShutdown = result != 'no';
+ else
+ this._haveShutdown = false;
+
+ if (this._haveShutdown)
+ this._powerOffItem.actor.show();
+ else
+ this._powerOffItem.actor.hide();
+
+ this._updateVisibility();
+ }));
+ } else {
+ this._consoleKitManager.CanStopRemote(Lang.bind(this,
+ function(result, error) {
+ if (!error)
+ this._haveShutdown = result;
+ else
+ this._haveShutdown = false;
+
+ if (this._haveShutdown) {
+ this._powerOffItem.actor.show();
+ } else {
+ this._powerOffItem.actor.hide();
+ }
+
+ this._updateVisibility();
+ }));
+ }
},
_updateHaveRestart: function() {
- this._consoleKitManager.CanRestartRemote(Lang.bind(this,
- function(result, error) {
- if (!error)
- this._haveRestart = result;
- else
- this._haveRestart = false;
-
- if (this._haveRestart) {
- this._restartItem.actor.show();
- } else {
- this._restartItem.actor.hide();
- }
- this._updateVisibility();
- }));
+ if (Systemd.haveSystemd()) {
+ this._systemdLoginManager.CanRebootRemote(Lang.bind(this,
+ function(result, error) {
+ if (!error)
+ this._haveRestart = result != 'no';
+ else
+ this._haveRestart = false;
+
+ if (this._haveRestart)
+ this._restartItem.actor.show();
+ else
+ this._restartItem.actor.hide();
+
+ this._updateVisibility();
+ }));
+ } else {
+ this._consoleKitManager.CanRestartRemote(Lang.bind(this,
+ function(result, error) {
+ if (!error)
+ this._haveRestart = result;
+ else
+ this._haveRestart = false;
+
+ if (this._haveRestart) {
+ this._restartItem.actor.show();
+ } else {
+ this._restartItem.actor.hide();
+ }
+
+ this._updateVisibility();
+ }));
+ }
},
_updateHaveSuspend: function() {
},
_onActivateRestart: function() {
- if (this._haveRestart)
+ if (!this._haveRestart)
+ return;
+
+ if (Systemd.haveSystemd())
+ this._systemdLoginManager.RebootRemote(true);
+ else
this._consoleKitManager.RestartRemote();
},
_onActivatePowerOff: function() {
- if (this._haveShutdown)
+ if (!this._haveShutdown)
+ return;
+
+ if (Systemd.haveSystemd())
+ this._systemdLoginManager.PowerOffRemote(true);
+ else
this._consoleKitManager.StopRemote();
}
});
--- /dev/null
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+
+const SystemdLoginManagerIface = <interface name='org.freedesktop.login1.Manager'>
+<method name='PowerOff'>
+ <arg type='b' direction='in'/>
+</method>
+<method name='Reboot'>
+ <arg type='b' direction='in'/>
+</method>
+<method name='CanPowerOff'>
+ <arg type='s' direction='out'/>
+</method>
+<method name='CanReboot'>
+ <arg type='s' direction='out'/>
+</method>
+</interface>;
+
+const SystemdLoginManagerProxy = Gio.DBusProxy.makeProxyWrapper(SystemdLoginManagerIface);
+
+function SystemdLoginManager() {
+ return new SystemdLoginManagerProxy(Gio.DBus.system,
+ 'org.freedesktop.login1',
+ '/org/freedesktop/login1');
+};
+
+function haveSystemd() {
+ return GLib.access("/sys/fs/cgroup/systemd", 0) >= 0;
+}